

import { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { DevGrid, DevPopup } from "~/public/cpas-ui";
import { StatSampleParameter } from "../../../typing";
import { consts } from "../../../consts";
import { getCpasPrimaryColor } from "@/utils/pub";
import { riskCoefficientColumns, riskCoefficientDataSource } from "./RiskCoefficientService";

//风险系数表

export const RiskCoefficientPopup = forwardRef((props: {
    statSampleParameter?: StatSampleParameter,
    setStatSampleParameter?: (value: StatSampleParameter) => void
}, ref) => {

    const [visible, setVisible] = useState<boolean>(false);
    const diaParams = useRef<any>();
    const dataGridRef = useRef<any>();

    // 自定义方法
    useImperativeHandle(ref, () => ({
        show: (params: any) => {
            diaParams.current = params;
            setVisible(true);
        }
    }))
    function onCancel() {
        setVisible(false)
        if (diaParams.current.setIsNeedPopup) {
            diaParams.current.setIsNeedPopup(false);
        }
    }

    return <>
        <DevPopup.Logic
            visible={visible}
            title='风险系数表'
            width={1024}
            height={"70%"}
            onHiding={onCancel}
            onCancel={onCancel}
            toolbarDisplay={false}
        >{() => {//必须用函数返回

            const acceptableRiskText = props.statSampleParameter?.acceptableRisk;
            const acceptableDevSizeText = props.statSampleParameter?.acceptableDevSize;

            return (<>
                <div style={{ marginBottom: 10, color: getCpasPrimaryColor() }}>
                    注：风险系数代表注册会计师愿意接受的误受风险。在确定可接受的误受风险时，审计人员需使用审计风险模型，即：可接受的风险=审计风险/(控制风险*分析程序风险），风险系数如下表:
                </div>
                <DevGrid.RangeTap
                    ref={dataGridRef}
                    className='devHeadersCenter PaperDevSortableGrid advancedQueryDataGrid'
                    dataSource={riskCoefficientDataSource}
                    height={'80%'}
                    keyExpr="acceptableDevSize"
                    isRemote={true}
                    showBorders={false}
                    showRowLines={true}
                    showColumnLines={true}
                    rowAlternationEnabled={true}
                    columns={riskCoefficientColumns}
                    paging={{ enabled: false }}
                  // scrolling={{ showScrollbar: 'never' }}

                />
                <div style={{ display: 'flex', alignContent: 'left', marginTop: 10, color: getCpasPrimaryColor() }}>
                    <div >
                        可接受的风险水平: {acceptableRiskText ? `【${acceptableRiskText}】` : consts.curNoValue}
                        可接受的偏差数量: {acceptableDevSizeText ? `【${acceptableDevSizeText}】` : consts.curNoValue}
                        对应值: {props.statSampleParameter?.riskCoefficient || consts.curNoValue}</div>
                </div>
            </>)
        }}
        </DevPopup.Logic >
    </>
});
